import {BrowserModule} from '@angular/platform-browser';
import {NgModule} from '@angular/core';
import {TranslateModule} from '@ngx-translate/core';
import {TranslateHttpLoader} from '@ngx-translate/http-loader';
import {HttpClient, HttpClientModule} from '@angular/common/http';
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
import {RouterModule} from '@angular/router';
import {JWT_OPTIONS, JwtModule} from '@auth0/angular-jwt';
import {FormsModule} from '@angular/forms';
import {NgZorroAntdModule} from 'ng-zorro-antd';

import {AppComponent} from './app.component';
import {AuthService} from './_services/auth.service';
import {UserService} from './_services/user.service';

export function HttpLoaderFactory(http: HttpClient) {
  return new TranslateHttpLoader(http);
}

export function jwtOptionsFactory(authService: AuthService) {
  return {
    tokenGetter: () => {
      return authService.jwtToken;
    },
    whitelistedDomains: ['qcloud.housir.vip:8080']
  };
}
@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    FormsModule,
    HttpClientModule,
    TranslateModule.forRoot(),
    JwtModule.forRoot({
      jwtOptionsProvider: {
        provide: JWT_OPTIONS,
        useFactory: jwtOptionsFactory,
        deps: [AuthService]
      }
    }),
    RouterModule.forRoot([
      {path: '', redirectTo: 'index', pathMatch: 'full'},
      {path: 'index', loadChildren: './index/index.module#IndexModule'},
      {path: 'account', loadChildren: './account/account.module#AccountModule'},
      {path: 'user', loadChildren: './user-center/user-center.module#UserCenterModule'},
      {path: 'exam-center', loadChildren: './exam-system/exam-center/exam-center.module#ExamCenterModule'},
      {path: 'exam-system', loadChildren: './exam-system/exam/exam-system.module#ExamSystemModule'},
      {path: '**', redirectTo: 'index'}
    ]),
    NgZorroAntdModule.forRoot()
  ],
  providers: [AuthService, UserService],
  bootstrap: [AppComponent]
})
export class AppModule {
}
